package com.xinruke.hostels.reservation.user.interfaces.api;

import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.po.MhHuiyuanQinshu;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.user.interfaces.dto.*;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

/**
 * @ClassName LoginFallback
 * @CreateDate 2019/6/12
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 登录API熔断
 */
@Component
public class ReservationUeserFallback implements FallbackFactory<ReservationUserApi> {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FeignFallback feignFallback;

    @Override
    public ReservationUserApi create(Throwable throwable) {
        logger.error("系统异常", throwable);

        return new ReservationUserApi() {
            @Override
            public ResultVO loginValidate(LoginReservationValidateDTO loginValidateDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "loginValidate", "登录验证");
            }

            @Override
            public ResultVO<LoginUserInfoQueryResultDTO> getLoginUserInfo(@Valid LoginUserInfoQueryDTO loginUserInfoQueryDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "getLoginUserInfo", "添加常用联系人");
            }

            @Override
            public ResultVO addContacts(@Valid ContactsAddInfoDto params) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "addContacts", "添加常用联系人");
            }

            @Override
            public ResultVO<RowsDataVO<ContactsInfo>> contactsList(ContactsListQueryDTO contactsListQueryDto) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "contactsList", "查看常用联系人");
            }

            @Override
            public ResultVO updateContacts(@Valid ContactsUpdateDto params) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "updateContacts", "修改常用联系人手机号");
            }

            @Override
            public ResultVO update(@Valid PersonalUpdateDto params) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "update", "修改个人信息");
            }

            @Override
            public ResultVO delContacts(@Valid ContactsDelDto params) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "delContacts", "删除常用联系人");
            }

            @Override
            public ResultVO<UserInfoQueryResultDTO> getUserDetail(@Valid UserDetailQueryDto userInfoQueryDTO) {
                return feignFallback.doFallback(UserDetailQueryDto.class, "delContacts", "得到用户详情");
            }

            @Override
            public ResultVO<MhHuiyuanQinshu> getMhHuiyuanQinshu(@Valid ContactsDetailQueryDTO queryDTO) {
                return feignFallback.doFallback(UserDetailQueryDto.class, "getMhHuiyuanQinshu", "联系人详情");
            }

            @Override
            public ResultVO<RowsDataVO<MemberDetailQuertResultDTO>> memberList(@Valid MemberListQueryDTO memberListQueryDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "memberList", "查看会员列表");
            }

            @Override
            public ResultVO<MemberDetailQuertResultDTO> detailById(@Valid MemberDetailQueryByIdDTO memberDetailQueryByIdDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "detailById", "根据ID查询会员信息");
            }

            @Override
            public ResultVO<ContactsDetailResultDto> contactDetailInnerAPI(@Valid ContactsDetailQueryDTO queryDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "contactDetailInnerAPI", "根据ID查询亲属联系人信息");
            }

            @Override
            public ResultVO<RowsDataVO<ContactsInfo>> contactsListInnerAPI(@Valid ContactsListQueryDTO contactsListQueryDto) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "contactsListInnerAPI", "根据会员ID查询亲属联系人列表");
            }

            @Override
            public ResultVO<BlacklistQueryResultDTO> isBlacklist(@Valid BlacklistQueryDTO blacklistQueryDTO) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "isBlacklist", "查询是否为黑名单用户");
            }

            @Override
            public ResultVO addMember(@Valid MemberAddDTO params) {
                return feignFallback.doFallback(ReservationUeserFallback.class, "addMember", "新增会员信息");
            }
        };
    }
}
